package com.woquyin.controller.api;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.BeanUtils;

import com.jfinal.core.Controller;
import com.jfinal.json.FastJson;
import com.jfinal.plugin.activerecord.Page;
import com.woquyin.interceptor.ParamInterceptor;
import com.woquyin.model.BizBanner;
import com.woquyin.model.BizTemplet;
import com.woquyin.model.BmTypeCode;
import com.woquyin.vo.ReturnData;
import com.woquyin.vo.HomeVo;
import com.woquyin.vo.home.HomeQueryVo;

public class IndexController extends Controller {
	public void index(){
		setAttr("userInfo", getSession().getAttribute("userInfo"));
		HomeVo vo = BmTypeCode.dao.queryVo();
		vo.setBannerList(BizBanner.dao.findAll());
		HomeQueryVo queryVo = new HomeQueryVo();
		queryVo.setPageNumber(1);
		vo.setTempletList(BizTemplet.dao.query(queryVo));
		setAttr("vo", vo);
		getSession().setAttribute("queryVo", queryVo);
		renderJsp("index.jsp");
	}
	
	/**
	 * 筛选
	 */
	public void query() {
		String jsonString = getAttrForStr(ParamInterceptor.REQUEST_JSON);
		HomeQueryVo queryVo2 = (HomeQueryVo)getSession().getAttribute("queryVo");
		HomeQueryVo queryVo1 = FastJson.getJson().parse(jsonString, HomeQueryVo.class);
		System.out.println(queryVo1);
		System.out.println(queryVo2);
		try {
			BeanUtils.copyProperties(queryVo2, queryVo1);
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(queryVo1);
		System.out.println(queryVo2);
		ReturnData<Page<BizTemplet>> resp = new ReturnData<>();
		HomeVo vo = BmTypeCode.dao.queryVo();
		vo.setBannerList(BizBanner.dao.findAll());
		vo.setTempletList(BizTemplet.dao.query(queryVo2));
		setAttr("vo", vo);
		getSession().setAttribute("queryVo", queryVo2);
		renderJsp("index.jsp");
	}
}
